package com.example.mytestdemo.utils

import android.content.Context
import android.util.DisplayMetrics
import android.util.Log
import android.view.View
import android.view.View.MeasureSpec
import android.view.WindowManager
import com.example.mytestdemo.linearlayoutmanager.MyView

/**
 * @author tgw
 * @date 2022/7/4
 * @describe
 */
object ScreenUtils {


    fun getScreenWidth(context: Context): Int {
        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        if (windowManager != null) {
            val outMetrics = DisplayMetrics()
            windowManager.defaultDisplay.getRealMetrics(outMetrics)
            return outMetrics.widthPixels
        }
        return 0
    }

    fun getScreenHeight(context: Context): Int {
        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        if (windowManager != null) {
            val outMetrics = DisplayMetrics()
            windowManager.defaultDisplay.getRealMetrics(outMetrics)
            return outMetrics.heightPixels
        }
        return 0
    }

    fun measureMode(tag:String,measureSpec: Int){
       val measureMode =View.MeasureSpec.getMode(measureSpec)
        when (measureMode) {
            View.MeasureSpec.EXACTLY -> {
                Log.d(tag, "tgw onMeasure widthMode: EXACTLY")

            }
            View.MeasureSpec.AT_MOST -> {
                Log.d(tag, "tgw onMeasure widthMode: AT_MOST")

            }
            View.MeasureSpec.UNSPECIFIED -> {
                Log.d(tag, "tgw onMeasure widthMode: UNSPECIFIED")
            }

        }
        var  specSize
                : Int = MeasureSpec.getSize(measureSpec)
        Log.d(tag, "tgw onMeasure specSize: $specSize")


    }

}